/**
 * LoginAction.java
 *2013-9-23上午12:14:15
 *LINKT
 */
package com.jskj.actions;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.jskj.bean.Swjg;
import com.jskj.bean.User;
import com.jskj.commons.BaseAction;
import com.jskj.dao.DaoSwjg;
import com.jskj.dao.DaoUser;

/**
 * @author LINKT
 *
 */
public class LoginAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private String userpwd;
	
        private static Logger log=Logger.getLogger(LoginAction.class);
        
        
        public String getUsername() {
			return username;
		}


		public void setUsername(String username) {
			this.username = username;
		}


		public String getUserpwd() {
			return userpwd;
		}


		public void setUserpwd(String userpwd) {
			this.userpwd = userpwd;
		}


		public void login() {
                HttpServletRequest res=ServletActionContext.getRequest();
                HttpServletResponse resp=ServletActionContext.getResponse();
                HttpSession session=res.getSession(true);
                if (username!=null && !username.equals("")) {
                        User user=new User();
                        Swjg swjg=new Swjg();
                        DaoUser dUser=new DaoUser();
                        DaoSwjg dSwjg=new DaoSwjg();
                        user=dUser.getUserForLogin(username, userpwd);
                        if (user.getfLogName()!=null && !user.getfLogName().equals("")) {//登陆成功
                                swjg=dSwjg.getSwjgForID(user.getSWJG_DM());
                                session.setAttribute("username", username);
                                session.setAttribute("userpwd", userpwd);
                                session.setAttribute("swry_mc", user.getfUserName());
                                session.setAttribute("isadmin", user.getfPower());
                                session.setAttribute("swjg_dm", swjg.getSWJG_DM());
                                session.setAttribute("swjg_mc", swjg.getSWJG_MC()); 
                                session.setAttribute("xzqh_dm", swjg.getXZQH_DM()); 
                                log.info("用户登录成功！");
                                try {
                                        resp.sendRedirect("mainAction.action");
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }else {
                                try {
                                        resp.sendRedirect("login.jsp");
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                }else{
                        try {
                                resp.sendRedirect("login.jsp");
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
        }
		public void login1() {
	                HttpServletRequest res=ServletActionContext.getRequest();
	                HttpServletResponse resp=ServletActionContext.getResponse();
	                HttpSession session=res.getSession(true);
	                if (username!=null && !username.equals("")) {
                                session.setAttribute("username", username);
                                session.setAttribute("userpwd", userpwd);
                                session.setAttribute("swry_mc", "张三");
                                session.setAttribute("isadmin", "1");
                                session.setAttribute("swjg_dm", "10000");
                                session.setAttribute("swjg_mc", "邢台国税局"); 
	                        log.info("用户登录成功！");
                                try {
                                        resp.sendRedirect("mainAction.action");
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
	                }else{
	                        try {
	                                resp.sendRedirect("login.jsp");
	                        } catch (IOException e) {
	                                // TODO Auto-generated catch block
	                                e.printStackTrace();
	                        }
	                }
	        }
}
